Skip to content

[GH-2830] Add Geography dual-dispatch to ST_AsText#2849

Merged
jiayuasu merged 2 commits into
apache:masterfrom
zhangfengcdt:feature/geography.support.st_astext
Apr 23, 2026
Merged

[GH-2830] Add Geography dual-dispatch to ST_AsText#2849
jiayuasu merged 2 commits into
apache:masterfrom
zhangfengcdt:feature/geography.support.st_astext

Conversation

@zhangfengcdt

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

  • Yes, and the PR name follows the format [GH-XXX] my subject. Closes #<issue_number>

What changes were proposed in this PR?

How was this patch tested?

  • mvn -pl common -am test -Dtest=FunctionTest
  • New Spark SQL case in GeographyFunctionTest

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation.

- L1 — JTS delegation via getJTSGeometry().toText()
- 1 new Spark SQL test
- update document

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Geography support to the existing ST_AsText Spark SQL expression via dual-dispatch, so it returns WKT for both Geometry and Geography inputs (Geography path delegates to common.geography.Functions.asText).

Changes:

  • Added Geography overload wiring for ST_AsText in Spark SQL expressions.
  • Added Functions.asText(Geography) implementation in common Geography functions.
  • Added/updated docs and added new unit/integration tests for ST_AsText on Geography.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala Dual-dispatches ST_AsText to Geometry (asWKT) or Geography (common.geography.Functions.asText).
common/src/main/java/org/apache/sedona/common/geography/Functions.java Implements asText(Geography) by converting to JTS and calling toText().
common/src/test/java/org/apache/sedona/common/Geography/FunctionTest.java Adds unit tests for Functions.asText (point, polygon, null).
spark/common/src/test/scala/org/apache/sedona/sql/geography/GeographyFunctionTest.scala Adds Spark SQL integration test for ST_AsText on Geography.
docs/api/sql/geography/Geography-Functions/ST_AsText.md Adds Geography documentation page for ST_AsText.
docs/api/sql/geography/Geography-Functions.md Adds ST_AsText entry to the Geography functions index.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/api/sql/geography/Geography-Functions/ST_AsText.md Outdated
Comment thread docs/api/sql/geography/Geography-Functions.md Outdated
/** Return the WKT text representation of a geography. */
public static String asText(Geography g) {
if (g == null) return null;
return toJTS(g).toText();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhangfengcdt This toJTS function seem to SerDe WKB one more time. Is it possible to avoid it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! toJTS(g) on WKBGeography does one WKB → JTS parse and caches the result in jtsGeometry (WKBGeography.java:116). Subsequent calls — both later asText invocations on the same row and any other JTS-path function (ST_NPoints, ST_GeometryType, ST_Centroid, ST_NumGeometries) — reuse the cached Geometry for free.

The alternative — g.toString() on the Geography — actually goes through WKBGeography.toString() getS2Geography().toString(), which populates the other cache (s2Geography), so it's worse when the current implementation.

A true zero-parse path (WKB → WKT walker) would need custom code since JTS doesn't expose it.

@zhangfengcdt zhangfengcdt marked this pull request as ready for review April 22, 2026 18:44
@jiayuasu jiayuasu merged commit 9e907a8 into apache:master Apr 23, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants